package tank;


import java.awt.*;

/**
 * @author kc
 * @date 2021/5/11 0011 0:19
 */
public class Explode {

    public static int WIDTH = ResourceMgr.explodes[0].getWidth();
    public static int HEIGHT = ResourceMgr.explodes[0].getHeight();

    private int x;
    private int y;

    private boolean living = true;

    TankFrame tf;

    private int step = 0;

    public Explode(int x, int y, TankFrame tf) {
        this.x = x;
        this.y = y;
        this.tf = tf;
        new Thread(Explode::run).start();
    }

    private static void run() {
        new Audio("audio/explode.wav").play();
    }

    public void paint(Graphics graphics) {
        if (!living) {
            tf.explodes.remove(this);
        }
        graphics.drawImage(ResourceMgr.explodes[step++], x, y, null);
        if (step >= ResourceMgr.explodes.length - 1) {
            living = false;
        }
    }
}
